package com.wh1200.mybatis.xmlless.starter

import com.wh1200.mybatis.xmlless.config.XmllessSqlInjector
import com.wh1200.mybatis.xmlless.inter.CurrentUserInfoProvider
import com.wh1200.mybatis.xmlless.plugin.CurrentUserInterceptor
import com.wh1200.mybatis.xmlless.plugin.SqlConvertInterceptor
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

/**
 *
 * @author 吴昊
 * @date 2023/12/20 10:50
 * @since v4.0.0
 * @version 1.0
 */
@Configuration
class XmllessConfiguration {

  @Bean
  fun sqlInjector(): XmllessSqlInjector {
    return XmllessSqlInjector()
  }

  @Bean
  fun sqlConvertInterceptor(): SqlConvertInterceptor {
    return SqlConvertInterceptor()
  }


  @Bean
  @ConditionalOnBean(CurrentUserInfoProvider::class)
  fun auditInfoSupplier(
      auditService: CurrentUserInfoProvider<*>
  ): CurrentUserInterceptor {
    return CurrentUserInterceptor(auditService)
  }

}
